<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { login, membersinfo } from "@/utils/api";

onLaunch(async () => {
  console.info("App Launch");
  // 静默登录
  const res = await uni.login();
  const code = res.code;
  let param = {
    code: code,
    grant_type: "wx_mini_app",
  }

  login(param).then((res) => {
    if (res.code == "1") {
      uni.setStorageSync("token_type", res.data.token_type);
      uni.setStorageSync("token", res.data.access_token);

      membersinfo().then((meinfo) => {
        uni.setStorageSync("userinfo", JSON.stringify(meinfo.data));
        uni.setStorageSync("mobile", meinfo.data.mobile);
        uni.setStorageSync("userId", meinfo.data.id);
        uni.setStorageSync("nickName", meinfo.data.nickName);
        // 是否已经实名认证
        uni.setStorageSync("auditStatus", meinfo.data.memberCertificate.auditStatus);
      });
    }
  })
});
onShow(() => {
  console.info("App Show");
});
onHide(() => {
  console.info("App Hide");
});
</script>
<style lang="scss">
  /* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
  @import "uview-plus/index.scss";
  @import "static/css/base.scss";
  @import "@/static/css/cssMixins.scss";
  @import "@/static/css/common.scss";
  page {
    background: #f7f7f7;
  }
</style>
